package uscdb.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

@Entity
@Table(name = "tuser")
@DynamicInsert(true)
@DynamicUpdate(true)
public class Tuser implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -164185064939156228L;
	private String id;
	/**
	 * 工号
	 */
	private String sid;
	private Date createdatetime;
	private Date modifydatetime;
	/**
	 * 姓名
	 */
	private String name;
	/**
	 * 密码
	 */
	private String pwd = "";

	/**
	 * 该用户的总review数
	 */
	private Integer totalReviewNum = 0;

	/**
	 * 一个用户可以有多个review
	 */
	private Set<Tusertreview> tusertreviewSet = new HashSet<Tusertreview>();

	@Id
	@Column(name = "ID", nullable = false, length = 36)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "sid", unique = true, nullable = false, length = 100)
	public String getSid() {
		return sid;
	}

	public void setSid(String sid) {
		this.sid = sid;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATEDATETIME", length = 19)
	public Date getCreatedatetime() {
		return createdatetime;
	}

	public void setCreatedatetime(Date createdatetime) {
		this.createdatetime = createdatetime;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "MODIFYDATETIME", length = 19)
	public Date getModifydatetime() {
		return modifydatetime;
	}

	public void setModifydatetime(Date modifydatetime) {
		this.modifydatetime = modifydatetime;
	}

	@Column(name = "name", length = 100)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "PWD", nullable = false, length = 100)
	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	@Column(name = "totalReviewNum")
	public Integer getTotalReviewNum() {
		return totalReviewNum;
	}

	public void setTotalReviewNum(Integer totalReviewNum) {
		this.totalReviewNum = totalReviewNum;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "tuser")
	public Set<Tusertreview> getTusertreviewSet() {
		return tusertreviewSet;
	}

	public void setTusertreviewSet(Set<Tusertreview> tusertreviewSet) {
		this.tusertreviewSet = tusertreviewSet;
	}

	public Tuser() {
	}

	/**
	 * 只要有工号则被认为是一个员工
	 * 
	 * @param id
	 * @param sid
	 * @param totalReviewNum
	 */
	public Tuser(String id, String sid, Integer totalReviewNum) {
		super();
		this.id = id;
		this.sid = sid;
		this.totalReviewNum = totalReviewNum;
	}

}
